<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- 引入 Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<title>学校列表</title>
<style>
#myInput {
	background-image: url('https://static.runoob.com/images/mix/searchicon.png'); /* 搜索按钮 */
	background-position: 10px 12px; /* 定位搜索按钮 */
	background-repeat: no-repeat; /* 不重复图片*/
	width: 50%;
	font-size: 16px; /* 加大字体 */
	padding: 12px 20px 12px 40px;
	border: 1px solid #ddd;
	margin-bottom: 12px;
	display:inline;
}
#header {
	border-bottom:#000 medium dashed;
}
#container {
}
.item {
	border-bottom:#000 thin dotted;
}
</style>
</head>

<body>
<div id="header">
  <input type="text" id="myInput" onkeyup="myFunction()" style="margin-left:20px" placeholder="搜索...">
  <span>
  <input type="button" value="搜索" class="btn btn-default" style="margin-left:40px"/>
  </span> <span>
  <input type="button" value="添加学校" class="btn btn-default" onclick="addSchool()" style="margin-left:40px"/>
  </span> </div>
<div id="container">
  <div class="item">
    <div><span style="margin-left:20px">成都理工大学</span> <span>
      <button id="modify" style="margin-left:40px" class="btn btn-default"  data-toggle="collapse" 
    data-target="#info">修改</button>
      </span> <span>
      <button  style="margin-left:40px" class="btn btn-default" >删除 </button>
      </span> 
      <span>
      <button  style="margin-left:40px" onclick="academy()" class="btn btn-default" >院级管理 </button>
      </span> 
      </div>
    <div id="info" class="collapse" role="form">
      <form class="form-horizontal" style="width:700px">
        <div class="form-group">
          <label class="control-label col-sm-2" for="name">院校名称：</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="name" value="成都理工大学" />
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-sm-2" for="province">所在省份：</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="province" value="四川省" />
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-sm-2" for="city">所在市区：</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="city" value="成都市" />
          </div>
        </div>
        <div class="form-group" style="margin:0 auto;display:block; width:100px">
        <button  class="btn btn-default"  id="ok">保存</button>
        </div>
      </form>
    </div>
  </div>
</div>
</body>
<script>
//实现添加学校
function addSchool()
{
	
	window.open("addSchool.html");
	
}
function academic()
{
	//需要传递一个学校对象给academicList
	window.open("academicList.html");
}
//加载所有学校
$().ready(function()
{
	$.post("/ulms_project/school/query",function(data)
	{
		var str="";
		var pre="num_"
		var id=0;
		var temp;
		$(data).each(function()
		{
			str+="<div class='item'><div><span style='margin-left:20px'>"+this.name+"</span> <span>"+
      "<button id='modify' style='margin-left:40px' class='btn btn-default'  data-toggle='collapse' "+
    "data-target=#"+pre+(++id)+">修改</button>"+
     " </span> <span>"+
      "<button  style='margin-left:40px' class='btn btn-default' >删除 </button>"+
      "</span> "+
      "<span>"+
      "<button  style='margin-left:40px' onclick='academic()' class='btn btn-default' >院级管理 </button>"+
      "</span> "+
      "</div>"+
    "<div id="+pre+(id)+" class='collapse' role='form'>"+
      "<form class='form-horizontal' style='width:700px'>"+
        "<div class='form-group'>"+
          "<label class='control-label col-sm-2' for='name'>院校名称：</label>"+
          "<div class='col-sm-10'>"+
            "<input type='text' class='form-control' id='name' value="+this.name+" />"+
          "</div>"+
        "</div>"+
        "<div class='form-group'>"+
         " <label class='control-label col-sm-2' for='province'>所在省份：</label>"+
          "<div class='col-sm-10'>"+
            "<input type='text' class='form-control' id='province' value="+this.p_name+" />"+
          "</div>"+
        "</div>"+
        "<div class='form-group'>"+
          "<label class='control-label col-sm-2' for='city'>所在市区：</label>"+
          "<div class='col-sm-10'>"+
            "<input type='text' class='form-control' id='city' value="+this.c_name+"/"+this.s_name+" />"+
         " </div>"+
        "</div>"+
        "<div class='form-group' style='margin:0 auto;display:block; width:100px'>"+
        "<button  class='btn btn-default'  id='ok'>保存</button>"+
        "</div>"+
      "</form>"+
   " </div>"+
  "</div>"
		});
		$("#container").html(str);
	});
});

//修改数据是调用
function modify()
{
	//获取当前对象的数据,+str是为了获取唯一标识
	var str=$(this).val();
	var name=("#name"+str).val();
	var province=("#province"+str).val();
	var city=("#city"+str).val();
	var area=("#area"+str).val();
	$.post("/ulms_project/school/modify",{name:name,province:province,city:city,area:area},function(data)
	{
		alert("修改成功！");
	});
}
//删除学校
function remove()
{
	//获取当前对象的数据,+str是为了获取唯一标识
	var str=$(this).val();//为id
	$.post("/ulms_project/school/remove",{id:str},function(data)
	{
		alert("删除成功！");
	});
}
//根据学校名字搜索学校
function queryByName()
{
	var name=$("#myInput");
	$.post("/ulms_project/school/queryByName",{name:name},function(data)
	{
		var str="";
		var pre="num_"
		var id=0;
		var temp;
		$(data).each(function()
		{
			str+="<div class='item'><div><span style='margin-left:20px'>"+this.name+"</span> <span>"+
      "<button id='modify' style='margin-left:40px' class='btn btn-default'  data-toggle='collapse' "+
    "data-target=#"+pre+(++id)+">修改</button>"+
     " </span> <span>"+
      "<button  style='margin-left:40px' class='btn btn-default' >删除 </button>"+
      "</span> "+
      "<span>"+
      "<button  style='margin-left:40px' onclick='academic()' class='btn btn-default' >院级管理 </button>"+
      "</span> "+
      "</div>"+
    "<div id="+pre+(id)+" class='collapse' role='form'>"+
      "<form class='form-horizontal' style='width:700px'>"+
        "<div class='form-group'>"+
          "<label class='control-label col-sm-2' for='name'>院校名称：</label>"+
          "<div class='col-sm-10'>"+
            "<input type='text' class='form-control' id='name' value="+this.name+" />"+
          "</div>"+
        "</div>"+
        "<div class='form-group'>"+
         " <label class='control-label col-sm-2' for='province'>所在省份：</label>"+
          "<div class='col-sm-10'>"+
            "<input type='text' class='form-control' id='province' value="+this.p_name+" />"+
          "</div>"+
        "</div>"+
        "<div class='form-group'>"+
          "<label class='control-label col-sm-2' for='city'>所在市区：</label>"+
          "<div class='col-sm-10'>"+
            "<input type='text' class='form-control' id='city' value="+this.c_name+"/"+this.s_name+" />"+
         " </div>"+
        "</div>"+
        "<div class='form-group' style='margin:0 auto;display:block; width:100px'>"+
        "<button  class='btn btn-default'  id='ok'>保存</button>"+
        "</div>"+
      "</form>"+
   " </div>"+
  "</div>"
		});
		$("#container").html(str);
	});
}

</script>
</html>
